<?php

class TemplateProcessor {

	private $oTemplate;

	public function __construct($sTemplateFileName) {

		if(!file_exists($sTemplateFileName)) {
			throw new Exception("Template " . $sTemplateFileName . " not found");
		}

		$oTemplateDocument = new DOMDocument();

		$oTemplateDocument->resolveExternals = true;
		$oTemplateDocument->substituteEntities = true;

		$oTemplateDocument->load($sTemplateFileName);

		$this->oTemplate = new XSLTProcessor();
		$this->oTemplate->importStyleSheet($oTemplateDocument);

	}

	/**
	 * applies xslt transformation
	 *
	 * @param DOMDocument $oDocument
	 * @return String
	 */
	public function process($oDocument) {

		return $this->oTemplate->transformToXML($oDocument);

	}

}

?>